package main

import (
	"github.com/inconshreveable/go-update"
	"net/http"
	"os/exec"
	"syscall"
)

func main()  {
	doUpdate("http://127.0.0.1/shuia/elastic/go_room.exe")
	//ctx, _ := context.WithCancel(context.Background())
	//cmd := exec.CommandContext(ctx, "./examples_test.exe")
	cmd := exec.Command( "./examples_test.exe")
	cmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
	//cmd.Stdout = os.Stdout
	cmd.Start()

	//time.Sleep(10 * time.Second)
	//fmt.Println("退出程序中...", cmd.Process.Pid)
	//cancel()
	//cmd.Wait()

}

func doUpdate(url string) error {
	resp, err := http.Get(url)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	err = update.Apply(resp.Body, update.Options{})
	if err != nil {
		// error handling
	}
	return err
}